package com.cskaoyan.mall.utils;

import com.cskaoyan.mall.service.lmpl.UserServiceImpl;
import com.google.gson.Gson;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
 * @ClassName: Json
 * @Description: TODO
 * @Auther 庄左
 * @Date 2022/7/3 18:56
 * @Version
 **/
public class Json {

    //获取json字符串
    public String getJsonString(HttpServletRequest req) throws IOException {
        ServletInputStream inputStream = req.getInputStream();
        //写入字节数组的输出流
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        int len = 0;
        byte[] bytes = new byte[1024];
        while ((len = inputStream.read(bytes)) != -1) {
            outputStream.write(bytes, 0, len);
        }
        //转为字符串
        return outputStream.toString("utf-8");
    }

}
